<!-- 地图 init 方法测试，loader 缓存测试 -->
<!DOCTYPE html>
<html lang="zh">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Map Demo</title>
    <link
      rel="stylesheet"
      href="https://a.amap.com/jsapi_demos/static/demo-center/css/demo-center.css"
    />
    <style>
      #map-container {
        width: 400px;
        height: 300px;
        border: 1px solid #ccc;
      }

      .map-wrapper {
        display: flex;
        flex-wrap: wrap;
      }

      .map-item {
        width: 45%;
        height: 400px;
        margin: 10px;
        border: 1px solid #ccc;
      }

      #huawei-map {
        width: 100%;
        height: calc(100% - 24px);
      }

      #google-map {
        width: 100%;
        height: calc(100% - 24px);
      }

      #amap-map {
        width: 100%;
        height: calc(100% - 24px);
      }

      .map-item-title {
        display: flex;
        justify-content: center;
      }
    </style>
  </head>

  <body>
    <div class="map-wrapper">
      <div class="map-item">
        <div class="map-item-title">华为地图</div>
        <div id="huawei-map"></div>
      </div>
      <div class="map-item">
        <div class="map-item-title">谷歌地图</div>
        <div id="google-map"></div>
      </div>
      <div class="map-item">
        <div class="map-item-title">高德地图</div>
        <div id="amap-map"></div>
      </div>
    </div>

    <script type="module">
      import { createMap, init } from "../src/index";

      (async () => {
        try {
          const YOUR_HUAWEI_MAP_API_KEY =
            "DgEDAF4hteXC0Zy9zEgKIGXiALRk5J81YmepSE98ByZVMQU+AL+NbgIbgXhcbbXHCTkFmmqbHRuSWUx6qRi3xcXozPZE0NJlpkeobg==";
          const YOUR_AMAP_API_KEY =
            "6f7f9957bd5b32dd518eb03f5910f42c";
          const YOUR_GOOGLE_MAP_API_KEY =
            "AIzaSyAR1VWmtaFPFaool39iVbPueS7DVRAn39k";

          const initCommonMapOption = {
            center: { lat: 28.190884, lng: 112.81362 },
            zoom: 12,
          };
          const huaweiMap = await init({
            container: document.getElementById("huawei-map"),
            mapProvider: "huawei",
            apiKey: YOUR_HUAWEI_MAP_API_KEY,
            ...initCommonMapOption,
          });

          const amapMap = await init({
            container: document.getElementById("amap-map"),
            mapProvider: "amap",
            apiKey: YOUR_AMAP_API_KEY,
            ...initCommonMapOption,
          });

          const googleMap = await init({
            container: document.getElementById("google-map"),
            mapProvider: "google",
            apiKey: YOUR_GOOGLE_MAP_API_KEY,
            ...initCommonMapOption,
          });

          const commonOptions = {
            position: { lat: 28.190884, lng: 112.81362 },
            zIndex: 10,
            draggable: false,
            title: "wzf",
            label: {
              color: "red",
              content: "cs",
              fontSize: "20px",
            },
            // icon: "../src/assets/images/location-icon.png"
            icon: {
              size: [20, 20],
              url: "../src/assets/images/location-icon.png",
            },
            customData: {
              test: 'test'
            }
          };

          setTimeout(async () => {
            console.log("添加 marker");
            const huaweiMarker = await huaweiMap.addMarker({
              ...commonOptions,
              animation: "DROP",
            });
            const amapMarker = await amapMap.addMarker({
              ...commonOptions,
            })
            const googleMarker = await googleMap.addMarker(commonOptions);

            console.log(huaweiMarker.getPropertiesUinified(), "----->>>>> huaiwei properties")
            console.log(amapMarker.getPropertiesUinified(), "----->>>>> amap properties")
            console.log(googleMarker.getPropertiesUinified(), "----->>>>> google properties")

            setTimeout(() => {
              console.log("删除 marker");
              huaweiMap.removeMarker(huaweiMarker);
              amapMap.removeMarker(amapMarker);
              googleMap.removeMarker(googleMarker);
            }, 2000);
          }, 2000);
        } catch (error) {
          console.error("Map initialization failed:", error);
        }
      })();
    </script>
  </body>
</html>